package com.example.springboot.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springboot.common.Result;
import com.example.springboot.entity.Order;
import com.example.springboot.service.IOrderService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Resource
    private IOrderService orderService;

    @GetMapping
    public Result findAll() {
        return Result.success(orderService.list());
    }

    @GetMapping("/state")
    public Result findState(@RequestParam(defaultValue = "") Integer orderUser,
                            @RequestParam(defaultValue = "") String orderState) {
        return Result.success(orderService.listState(orderUser,orderState));
    }


    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize,
                           @RequestParam(defaultValue = "") String orderId,
                           @RequestParam(defaultValue = "") Integer orderUser,
                           @RequestParam(defaultValue = "") String orderState){
        return Result.success(orderService.findPage(new Page<>(pageNum, pageSize),orderId,orderUser,orderState));
    }

    @PostMapping
    public Result save(@RequestBody Order order){
        return Result.success(orderService.saveOrUpdate(order));
    }


}
